--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--[[

    跨存档数据储存


]]--
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---
    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---
    local data_sheet_index = "hutao_client_side_data_sheet" -- 存档数据表索引
    local function GetData(index,default)
        local data = {}
        TheSim:GetPersistentString(data_sheet_index, function(load_success, str_data)
            if load_success and str_data then
                local crash_flag,temp_data = pcall(json.decode,str_data)
                if crash_flag then
                    data = temp_data
                end
            end
        end)
        return data[index] or default
    end
    local function SetData(index,value)
        local data = {}
        TheSim:GetPersistentString(data_sheet_index, function(load_success, str_data)
            if load_success and str_data then
                local crash_flag,temp_data = pcall(json.decode,str_data)
                if crash_flag then
                    data = temp_data
                end
            end
        end)
        data[index] = value
        local str = json.encode(data)
        TheSim:SetPersistentString(data_sheet_index, str, false, function()
            print("info hutao_client_side_data_sheet SAVED!")
        end)
    end
    local function Get_Cross_Archived_Data_By_userid(userid)
        return GetData(userid) or {}
    end

    local function Set_Cross_Archived_Data_By_userid(userid,_table)
        SetData(userid,_table)
    end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

TUNING.HUTAO_FNS = TUNING.HUTAO_FNS or {}

function TUNING.HUTAO_FNS:Get_Cross_Archived_Data_By_userid(userid)
    return Get_Cross_Archived_Data_By_userid(userid) or {}
end
function TUNING.HUTAO_FNS:Set_Cross_Archived_Data_By_userid(userid,_table) 
    Set_Cross_Archived_Data_By_userid(userid,_table) 
end
function TUNING.HUTAO_FNS:Set_ThePlayer_Cross_Archived_Data(index,value)
    if ThePlayer and ThePlayer.userid then
        local all_data = TUNING.HUTAO_FNS:Get_Cross_Archived_Data_By_userid(ThePlayer.userid) or {}
        all_data[index] = value
        TUNING.HUTAO_FNS:Set_Cross_Archived_Data_By_userid(ThePlayer.userid,all_data)
    end
end
function TUNING.HUTAO_FNS:Get_ThePlayer_Cross_Archived_Data(index)
    if ThePlayer and ThePlayer.userid then
        local all_data = TUNING.HUTAO_FNS:Get_Cross_Archived_Data_By_userid(ThePlayer.userid)
        return all_data[index] or nil
    end
    return nil
end
